import React, { useState } from 'react'
import QRCode from 'qrcode.react'
import axios from 'axios'

const LoginByQRCode = (props:any) => {
  const [QRCodeUrl, setQRCodeUrl] = useState('')
  const onGenerateQrcode = () => {
    // 获取二维码的url
    axios.get('请求后台的地址').then((res) => {
      // 根据后台返回的数据格式处理结果
      const data = res.data
      if (data.status === 'ok') {
        setQRCodeUrl(data.url)
      }
    })
  }

  return (
    <>
      <div>
        {/*<button
          style={{
            background: '#1890ff',
            color: '#fff',
            border: 'none',
            padding: '8px 15px',
            marginBottom: 20,
            pointerEvents: 'auto',
            cursor: 'pointer',
          }}
          onClick={onGenerateQrcode}>
          生成二维码
        </button>*/}
        <QRCode value={props.scanLogin.code} size={160} />
      </div>
    </>
  )
}

export default LoginByQRCode
